<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.io.*" %>
<%!
public int copy(InputStream input, OutputStream output)
		throws IOException {
	byte[] buffer = new byte[1024];
	int count = 0;
	int n = 0;
	
	while (-1 != (n = input.read(buffer))) {
	    output.write(buffer, 0, n);
	    count += n;
	}
	
	return count;
}

public static class FileStreamInfo {

	 /**
    * The content type for this stream.
    */
   private String contentType;

   /**
    * The file to be downloaded.
    */
   private File file;

   /**
    * Constructs an instance of this class, based on the supplied
    * parameters.
    *
    * @param contentType The content type of the file.
    * @param file        The file to be downloaded.
    */
   public FileStreamInfo(String contentType, File file) {
       this.contentType = contentType;
       this.file = file;
   }

   /**
    * Returns the content type of the stream to be downloaded.
    *
    * @return The content type of the stream.
    */
   public String getContentType() {
       return this.contentType;
   }

   /**
    * Returns an input stream on the file to be downloaded. This stream
    * will be closed by the <code>DownloadAction</code>.
    *
    * @return The input stream for the file to be downloaded.
    * @throws IOException if an error occurs
    */
   public InputStream getInputStream()
       throws IOException {
       FileInputStream fis = new FileInputStream(file);
       BufferedInputStream bis = new BufferedInputStream(fis);

       return bis;
   }


}
%>
<%
	String filename = "";
	String tempURLtt = request.getParameter("url");
	try {
		filename = tempURLtt.substring(tempURLtt.lastIndexOf("/")+1);
		System.out.println(filename);
		new String(filename.getBytes(),"iso-8859-1");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	response.setHeader("Content-disposition", 
	        "attachment; filename="+filename);
	String contentType = "application/x-msdownload";
	File file = new File(tempURLtt);
	
	FileStreamInfo info = new FileStreamInfo(contentType, file);
	    InputStream stream = info.getInputStream();
	
	    try {
	        response.setContentType(contentType);
	        copy(stream, response.getOutputStream());
	    } finally {
	        if (stream != null) {
	            stream.close();
	        }
	    }
%>

